//
//  DaishouDetailCell.m
//  TengyunStation
//
//  Created by Johnny on 15/10/27.
//  Copyright © 2015年 xingrong. All rights reserved.
//

#import "DaishouDetailCell.h"
#import "TSHeader.h"
#import "DaishouExpress.h"

@implementation DaishouDetailCell

- (void)awakeFromNib {
    // Initialization code
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, 63.5, 320, 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)reloadDaishouDetailCell:(DaishouExpress *)express isShowAddress:(BOOL)isShow {
    _expressIdLabel.text = [NSString stringWithFormat:@"运单号:%@",express.expressId];
    _telephoneLabel.text = [NSString stringWithFormat:@"收件人:%@",express.telephone];
    if (isShow) {
        _addressLabel.textColor = AssistTextColor;
        _addressLabel.text = express.address;
    } else {
        _addressLabel.attributedText = [self attrString:express.position Address:express.address];
//        NSMutableString *allString = [[NSMutableString alloc] init];
//        if (express.position.length > 0) {
//            [allString appendString:express.position];
//            if (express.address.length > 0) {
//                [allString appendString:[NSString stringWithFormat:@"/%@",express.address]];
//            }
//        } else {
//            [allString appendString:express.address];
//        }
//        _addressLabel.text = allString;
    }
}

- (NSAttributedString *)attrString:(NSString *)position Address:(NSString *)address {
    NSMutableString *allString = [[NSMutableString alloc] initWithString:position];
    if (address.length > 0) {
        [allString appendString:[NSString stringWithFormat:@"/%@",address]];
    }
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:allString];
    NSRange range = [allString rangeOfString:position];
    [attrString addAttribute:NSForegroundColorAttributeName value:OrangeColor range:range];
    return attrString;
}

@end
